package com.bridgetree.jubaocrm.ui;

import android.app.Application;
import android.content.Context;
import android.widget.Toast;

import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.MKGeneralListener;
import com.baidu.mapapi.map.MKEvent;

public class JubaoCRMApplication extends Application {
	private static JubaoCRMApplication mInstance;
	public boolean mbKeyRight = true;
	public BMapManager mBMapManager;

//	public static final String strKey = "71Nka4jPiA8b5AXpLxOlS2iQ";//公司
	//public static final String strKey = "ymRdWYRNZOWejzRK2m0CdgS5";//家
	//public static final String strKey = "yZPabxISGTLpIziNP0D39FtD";//山脉公司
	public static final String strKey = "pUeChlgd7QNImPoREqoNT89Z";//山脉公司发布
	@Override
	public void onCreate() {
		super.onCreate();
		mInstance = this;
		initEngineManager(this);
	}

	public void initEngineManager(Context context) {
		if (mBMapManager == null) {
			mBMapManager = new BMapManager(context);
		}

		if (!mBMapManager.init(strKey, new MyGeneralListener())) {
			Toast.makeText(
					JubaoCRMApplication.getInstance().getApplicationContext(),
					"BMapManager  初始化错误!", Toast.LENGTH_LONG).show();
		}
	}

	public static JubaoCRMApplication getInstance() {
		return mInstance;
	}

	public static class MyGeneralListener implements MKGeneralListener {

		@Override
		public void onGetNetworkState(int iError) {
			if (iError == MKEvent.ERROR_NETWORK_CONNECT) {
				Toast.makeText(
						JubaoCRMApplication.getInstance().getApplicationContext(),
						"您的网络出错啦！", Toast.LENGTH_LONG).show();
			} else if (iError == MKEvent.ERROR_NETWORK_DATA) {
				Toast.makeText(
						JubaoCRMApplication.getInstance().getApplicationContext(),
						"输入正确的检索条件！", Toast.LENGTH_LONG).show();
			}
			// ...
		}

		@Override
		public void onGetPermissionState(int iError) {
			// 非零值表示key验证未通过
			if (iError != 0) {
				// 授权Key错误：
//				Toast.makeText(
//						JubaoCRMApplication.getInstance().getApplicationContext(),
//						"请输入正确Key！error: "+ iError, Toast.LENGTH_LONG).show();
				JubaoCRMApplication.getInstance().mbKeyRight = false;
			} else {
				JubaoCRMApplication.getInstance().mbKeyRight = true;
//				Toast.makeText(
//						DemoApplication.getInstance().getApplicationContext(),
//						"key认证成功", Toast.LENGTH_LONG).show();
			}
		}
	}

}